@ECHO OFF
SET PATH=D:\Tools\CS\bin;D:\Tools\WinAVR\utils\bin;%PATH%

CD %1

SET BOARD=maple_RET6
SET MEMORY_TARGET=flash
SET LIB_MAPLE_HOME=../libmaple
REM SET BUILD_PATH=../build

IF "*%3"=="*" goto :BUILD
IF "%3"=="clean" goto :CLEAN
IF "%3"=="rebuild" goto :REBUILD

:BUILD
make.exe 2>&1 | "%SystemRoot%\system32\find" " error: " | sed -e "s:/:\\:g" -e "s/\.c:\([0-9]*\):\([0-9]*\):/.c$(\1,\2):/" -e "s/\.h:\([0-9]*\):\([0-9]*\):/.h$(\1,\2):/" -e "s/ error: / error: /" -e "s/ note: / warning: /" > error.txt
@for /F "tokens=1,2 delims=$" %%l in (error.txt) do @echo %%~dpnxl %%m
rem del error.txt /Q
CD ..
EXIT 0

:REBUILD
call :CLEAN
goto :BUILD

:CLEAN
rmdir /S /Q libmaple
make.exe clean
CD ..
